import Joi, { PartialSchemaMap } from 'joi'
import { isNotChineseCharactersAndSpace, isNumberLetterAndStartWithLetter, nickNameRegexp } from '../../utils/pattern'

export const isExistRule: PartialSchemaMap = {
  userName: Joi.string().required()
}
export const isExistEmailRule: PartialSchemaMap = {
  email: Joi.string().email().required()
}
export const registerRule: PartialSchemaMap = {
  userName: Joi.string()
    .max(10)
    .min(2)
    .pattern(isNumberLetterAndStartWithLetter, { name: '用户名必须由数字和字母组成，并以字母开头' })
    .required(),
  password: Joi.string()
    .max(16)
    .min(8)
    .pattern(isNotChineseCharactersAndSpace, { name: '密码必须非中文汉字组成,且不能包含空格' })
    .required(),
  nickName: Joi.string()
    .max(10)
    .min(2)
    .pattern(nickNameRegexp, { name: '昵称必须由数字或字母或中文或-_!@#$%^&*组成，并以字母或中文开头' })
    .required(),
  email: Joi.string().email().required(),
  emailKey: Joi.string().length(6).required(),
  gender: Joi.number().valid(0, 1, 2)
}
export const loginRule: PartialSchemaMap = {
  userNameOrEmail: Joi.string().required(),
  password: Joi.string().required()
}
export const sendEmailRule: PartialSchemaMap = {
  email: Joi.string().email().required()
}

export const updateUserinfoRule: PartialSchemaMap = {
  nickName: Joi.string()
    .max(10)
    .min(2)
    .pattern(nickNameRegexp, { name: '昵称必须由数字或字母或中文或-_!@#$%^&*组成，并以字母或中文开头' }),
  email: Joi.string().email(),
  emailKey: Joi.string().length(6),
  gender: Joi.number().valid(0, 1, 2),
  avatar: Joi.string().pattern(/^\/static\//, { name: '头像地址必须是以/static/开头的本服务器图片' })
}
export const createBlogRule: PartialSchemaMap = {
  image: Joi.array().items(Joi.string()),
  content: Joi.string().required()
}
export const createCommentRule: PartialSchemaMap = {
  content: Joi.string().required()
}
